<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加行程</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">添加行程</div>
                <div class="layui-card-body">
                        {if !empty($res)}
                    <h2 style="margin-left: 25px">详细行程 <a style="color: red">修改一个后 要点击这一个下面的修改按钮</a></h2>
                        {foreach $res as $k=>$v}
                        <div class="layui-form-item form-group" style="margin-top: 25px">
                            <label class="layui-form-label">*第几日</label>
                            <div class="layui-input-block">
                                <input type="text" name="sort_day" placeholder="第一天就写1" autocomplete="off"
                                       class="layui-input" value="{$v['sort_day']}" id="sort_day{$v['journey_id']}">
                            </div>
                            <label class="layui-form-label" style="margin-top: 35px">*景点</label>
                            <div class="layui-input-block" style="margin-top: 15px">
                                <textarea type="text" name="tour" placeholder="萤火虫水洞" autocomplete="off" class="layui-input"
                                          style="height: 80px" id="tour{$v['journey_id']}">{$v['tour']}</textarea>
                            </div>
                            <label class="layui-form-label" style="margin-top: 35px">*餐饮</label>
                            <div class="layui-input-block" style="margin-top: 15px">
                                <textarea id= "catering{$v['journey_id']}" type="text" name="catering" placeholder="餐饮：早餐自理、午餐（沂蒙炒鸡、干锅包菜、红 烧狮子
                                    头、时令水果、米饭/馒头）、晚餐自理" style="height: 80px" autocomplete="off" class="layui-input" >{$v['catering']}</textarea>
                            </div>
                            <label class="layui-form-label" style="margin-top: 35px">*住宿</label>
                            <div class="layui-input-block" style="margin-top: 15px">
                                <textarea id="living{$v['journey_id']}" type="text" name="living" placeholder="龙冈大酒店标准客房" autocomplete="off" class="layui-input" style="height: 80px">{$v['living']}</textarea>
                            </div>
                            <div class="layui-input-block">
                                <div class="layui-inline" style="margin-top: 15px;margin-bottom: 15px">
                                    <!--<button class="layui-btn layui-btn-normal" lay-submit="xc_commit" lay-filter="xc_commit">修改</button>-->
                                    <button class="layui-btn layui-btn-normal" onclick="update({$v['journey_id']})">修改</button>
                                    <button class="layui-btn layui-btn-danger" onclick="del({$v['journey_id']})">删除</button>
                                </div>
                            </div>

                        </div>
                        {/foreach}
                        {else}
                    <img src="/static/image/admin_null.png" style="position: relative;left: 35%"/>
                        {/if}
                    <div style="height: 100px"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script src="/static/js/jquery-1.11.1.min.js"></script>
<script>
    function update(i) {
        var loading = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        var sort_day = $("#sort_day"+i).val();
        var  id = i;
        var tour = $("#tour"+i).val();
        var catering = $("#catering"+i).val();
        var living = $("#living"+i).val();
        $.ajax({
            url: "{:url('Goods/editTravel')}",
            type: 'post',
            dataType: 'json',
            data: {id:id,sort_day:sort_day,tour:tour,catering:catering,living:living},
            success: function(data){
                if (data.code === 0) {
                    layer.close(loading);
                    layer.msg('修改成功',{icon:1,time:2000});
                }else if(data.code === 2){
                    layer.close(loading);
                    layer.msg('修改失败',{icon:2,time:1000})
                }
            }
        });
        return false;
    }

    function del(i) {
        var loading = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });

        var  id = i;

        $.ajax({
            url: "{:url('Goods/delTravel')}",
            type: 'post',
            dataType: 'json',
            data: {id:id},
            success: function(data){
                if (data.code === 0) {
                    layer.close(loading);
                    layer.msg('删除成功',{icon:1,time:2000},function f() {
                        window.location.reload();
                    });
                }else if(data.code === 2){
                    layer.close(loading);
                    layer.msg('删除失败',{icon:2,time:1000},function () {
                        window.location.reload();
                    })
                }
            }
        });
        return false;
    }
</script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','set','upload'], function(){
        $ = layui.jquery;
        var  admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,form = layui.form
            ,upload=layui.upload;

        form.render(null,'component-form-group');

        form.on('submit(xc_commit)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            console.log(data.field);
            $.ajax({
                url: "{:url('Goods/editTravel')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function(data){
                    if (data.code === 0) {
                        layer.close(loading);
                        layer.msg('添加成功',{icon:1,time:2000});
                    }else if(data.code === 2){
                        layer.close(loading);
                        layer.msg('添加失败',{icon:2,time:1000})
                    }else if(data.code ===1){
                        layer.close(loading);
                        layer.msg(data.msg,{icon:2,time:2000})
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        var $ = layui.$, active = {
            prex:function(){
                layer.confirm('确认取消本次编辑并返回吗？',function(){
                    window.location.href="{:url('Goods/goods')}";
                });
            }
        };

        $('.prex').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>


</body>
</html>